package com.oa.ylms.apps.business.file.impl;

import java.util.List;

import com.oa.ylms.apps.business.file.IFileCategoryService;
import com.oa.ylms.apps.constants.IDEDStates;
import com.oa.ylms.apps.dao.file.IFileCategoryDao;
import com.oa.ylms.apps.entity.file.FileCategoryValue;

public class FileCategoryServiceImpl implements IFileCategoryService {

	
	private IFileCategoryDao categoryDao;
	private FileCategoryValue fileCategory;
	
	// Service method
	@Override
	public int addFileCategory(String categoryName)throws Exception {
		fileCategory.setCategoryName(categoryName);
		fileCategory.setStates(IDEDStates.ENABLE);
		return categoryDao.addFileCategory(fileCategory);

	}

	@Override
	public boolean deleteFileCategory(int categoryId,int states) throws Exception {
		fileCategory = queryCategoryById(categoryId);
		fileCategory.setStates(IDEDStates.DELETE);
		return categoryDao.editFileCategory(fileCategory);

	}
	@Override
	public boolean modifyFileCategory(int categoryId, String categoryName,int states)
			throws Exception {
		fileCategory = queryCategoryById(categoryId);
		fileCategory.setCategoryName(categoryName);
		fileCategory.setStates(states);
		return categoryDao.editFileCategory(fileCategory);
	}
	@Override
	public List<FileCategoryValue> queryAllCategory() throws Exception {
		return categoryDao.queryCategoryByStates(fileCategory);
	}
	@Override
	public List<FileCategoryValue> queryCategoryByStates(Integer states) throws Exception{
		fileCategory.setStates(states);
		return categoryDao.queryCategoryByStates(fileCategory);
	}

	@Override
	public FileCategoryValue queryCategoryById(int categoryId) throws Exception {
		fileCategory.setCategoryId(categoryId);
		return categoryDao.queryCategoryById(fileCategory);
	}

	@Override
	public boolean toDisable(int categoryId) throws Exception {
		fileCategory=queryCategoryById(categoryId);
		fileCategory.setStates(IDEDStates.DISABLE);
		return categoryDao.editFileCategory(fileCategory);
	}

	@Override
	public boolean toEnable(int categoryId) throws Exception {
		fileCategory=queryCategoryById(categoryId);
		fileCategory.setStates(IDEDStates.ENABLE);
		return categoryDao.editFileCategory(fileCategory);
	}

	// Service property accessors
	
	public IFileCategoryDao getCategoryDao() {
		return categoryDao;
	}

	public void setCategoryDao(IFileCategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	public FileCategoryValue getFileCategory() {
		return fileCategory;
	}

	public void setFileCategory(FileCategoryValue fileCategory) {
		this.fileCategory = fileCategory;
	}

}
